﻿using CommonHelper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Order.MicroService.IService;
using Order.MicroService.Models;
using Order.MicroService.ViewModel;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mime;
using System.Threading.Tasks;

namespace Order.MicroService.Api.Controllers
{
    [Route("[controller]")]
    [ApiController]
    public class OrdersController : ControllerBase
    {
        private readonly IOrderService _orderService;
        public OrdersController(IOrderService orderService)
        {
            _orderService = orderService;
        }
        /// <summary>
        /// 获取所有订单数据
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetOrdersInfo")]
        public ApiResult<IEnumerable<Orders>> GetOrdersInfo()
        {
            return ApiResult<IEnumerable<Orders>>.SuccessResult(_orderService.GetOrdersInfo());
        }
        /// <summary>
        /// 新增一条订单数据
        /// </summary>
        /// <param name="orders"></param>
        /// <returns></returns>
        [HttpPost("AddOrders")]
        public ApiResult<int> AddOrders([FromForm] AddOrdersInfoDto orders)
        {
            return ApiResult<int>.SuccessResult(_orderService.AddOrders(orders));
        }

        /// <summary>
        /// 更新某一条订单的数据
        /// </summary>
        /// <param name="orders">数据实体</param>
        /// <returns></returns>
        [HttpPost("updateOrders")]
        public ApiResult<int> UpdateOrders(Orders orders)
        {
            return ApiResult<int>.SuccessResult(_orderService.UpdateOrders(orders));
        }
        [HttpGet("GetSumInfo")]
        public ApiResult<int> GetSumInfo()
        {
            return ApiResult<int>.SuccessResult(6);
        }

        //[HttpGet("GetSum")]
        //public void GetSum()
        //{
        //    var data = new int[] { 100000, 660,1000,1000,800,600,926,700,1200,1250,1300,350,2500,400,200,3000,2000,666,700,1000,1000,300,3000,400,1000,2000,400,1000};
        //    var sum = data.Sum();
        //    int result = 0;
        //    for (int i = 0; i < data.Length; i++)
        //    {
        //        result += data[i];
        //    }
        //    System.Console.WriteLine(sum);
        //    System.Console.WriteLine(result);
        //}
    }
}
